<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="业务员ID">
              <a-input placeholder="请输入业务员ID" v-model="queryParam.salesmanId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="业务员名称">
              <a-input placeholder="请输入业务员名称" v-model="queryParam.salesman"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!--<a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('销售业务员')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i>
        <span>已选择</span>
        <a style="font-weight: 600">
          {{ selectedRowKeys.length }}
        </a>
        <span>项</span>
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <!--<a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>-->
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <a-tabs defaultActiveKey="1">
      <a-tab-pane tab="客户欠款统计" key="1">
        <Bms-Debt-Customer-List ref="BmsDebtCustomerList"></Bms-Debt-Customer-List>
      </a-tab-pane>
    </a-tabs>

    <!-- 表单区域 -->
    <bmsSalesman-modal ref="modalForm" @ok="modalFormOk"/>

  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import BmsSalesmanModal from './modules/BmsSalesmanModal'
  import BmsDebtCustomerList from './MainDebtCustomerList'
  import BmsDebtCustomerModal from './modules/BmsDebtCustomerModal'
  import { filterObj } from '@/utils/util';

  export default {
    name: "BmsSalesmanList",
    mixins: [JeecgListMixin],
    components: {
      BmsDebtCustomerList,
      BmsDebtCustomerModal,
      BmsSalesmanModal
    },
    data () {
      return {
        isorter:{
        },
        description: '销售业务员管理页面',
        /* 分页参数 */
        ipagination:{
          current: 1,
          pageSize: 5,
          pageSizeOptions: ['5', '10', '20'],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        // 分页参数
        type: "radio",
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            customRender:function (t, r, index) {
              return parseInt(index)+1;
            }
          },
          {
            title: '业务员ID',
            align:"center",
            dataIndex: 'salesmanId'
          },
          {
            title: '业务员名称',
            align:"center",
            dataIndex: 'salesman'
          },
          {
            title: '维护客户数量',
            align:"center",
            dataIndex: 'customerCount'
          },
          {
            title: '客户欠款总额',
            align:"center",
            dataIndex: 'totalDebt'
          },
          {
            title: '剩余退款总额',
            align:"center",
            dataIndex: 'totalRefund'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
        // 请求参数
    	url: {
              list: "/inca/bmsSalesman/list",
              //delete: "/inca/bmsSalesman/delete",
              //deleteBatch: "/inca/bmsSalesman/deleteBatch",
              //exportXlsUrl: "inca/bmsSalesman/exportXls",
              //importExcelUrl: "inca/bmsSalesman/importExcel",
           },
        }
      },
      computed: {
        /*importExcelUrl: function(){
          return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
        }*/
      },
    methods: {
      getQueryParams() {
        //获取查询条件
        let sqp = {}
        if(this.superQueryParams){
          sqp['superQueryParams']=encodeURI(this.superQueryParams)
          sqp['superQueryMatchType'] = this.superQueryMatchType
        }
        let param = Object.assign(sqp, this.queryParam,this.filters);
        param.field = this.getQueryField();
        param.pageNo = this.ipagination.current;
        param.pageSize = this.ipagination.pageSize;
        return filterObj(param);
      },
      clickThenCheck(record) {
        return {
          on: {
            click: () => {
              this.onSelectChange(record.id.split(","), [record]);
            }
          }
        };
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectionRows;
        this.$refs.BmsDebtCustomerList.getOrderMain(this.selectedRowKeys[0]);
        //this.$refs.JeecgOrderTicketList.getOrderMain(this.selectedRowKeys[0]);
      },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
        this.$refs.BmsDebtCustomerList.queryParam.mainId = null;
        //this.$refs.JeecgOrderTicketList.queryParam.mainId = null;
        this.$refs.BmsDebtCustomerList.loadData();
        //this.$refs.JeecgOrderTicketList.loadData();
        this.$refs.BmsDebtCustomerList.selectedRowKeys = [];
        this.$refs.BmsDebtCustomerList.selectionRows = [];
        //this.$refs.JeecgOrderTicketList.selectedRowKeys = [];
        //this.$refs.JeecgOrderTicketList.selectionRows = [];
      },

      handleDelete: function (id) {
        var that = this;
        /*deleteAction(that.url.delete, {id: id}).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            that.loadData();
            this.$refs.JeecgOrderCustomerList.loadData();
            this.$refs.JeecgOrderTicketList.loadData();
          } else {
            that.$message.warning(res.message);
          }
        });*/
      },
      searchQuery:function(){
        this.selectedRowKeys = [];
        this.selectionRows = [];
        this.$refs.BmsDebtCustomerList.queryParam.mainId = null;
        //this.$refs.JeecgOrderTicketList.queryParam.mainId = null;
        this.$refs.BmsDebtCustomerList.loadData();
        //this.$refs.JeecgOrderTicketList.loadData();
        this.$refs.BmsDebtCustomerList.selectedRowKeys = [];
        this.$refs.BmsDebtCustomerList.selectionRows = [];
        //this.$refs.JeecgOrderTicketList.selectedRowKeys = [];
        //this.$refs.JeecgOrderTicketList.selectionRows = [];
        this.loadData();
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>